// Copyright (C) 2012 by Johann Duscher <jonny.dee@gmx.net>
//
// This file is part of barcodeart-pp.
//
// barcodeart-pp is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// barcodeart-pp is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with barcodeart-pp. If not, see <http://www.gnu.org/licenses/>.

#include "BorderDecorator.hpp"

namespace barcodeart
{

BorderDecorator::BorderDecorator(const IBarCode& delegate, int margin, bool black)
    : m_pDelegate(&delegate), m_black(black), m_margin(margin)
{
}

BorderDecorator::~BorderDecorator()
{
}

void BorderDecorator::setBlack(bool value)
{
    m_black = value;
}

bool BorderDecorator::isBlack() const
{
    return m_black;
}

void BorderDecorator::setMargin(int value)
{
    m_margin = value;
}

int BorderDecorator::getMargin() const
{
    return m_margin;
}

int BorderDecorator::getWidth() const
{
    return m_pDelegate->getWidth() + 2*m_margin;
}

int BorderDecorator::getHeight() const
{
    return m_pDelegate->getHeight() + 2*m_margin;
}

bool BorderDecorator::isBlack(int y, int x) const
{
    if (y < m_margin)
        return m_black;

    if (y >= m_margin + m_pDelegate->getHeight())
        return m_black;

    if (x < m_margin)
        return m_black;

    if (x >= m_margin + m_pDelegate->getWidth())
        return m_black;

    return m_pDelegate->isBlack(y - m_margin, x - m_margin);
}

}
